#include "stm32f10x.h"                  // Device header
#include "FlowLight.h"
#include "Delay.h"

#define ALL_LED_PINS (GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15)
static uint16_t led_pins[] = {GPIO_Pin_12,GPIO_Pin_13,GPIO_Pin_14,GPIO_Pin_15};
static uint8_t current_index = 0;

void FlowLight_Init(void)
{
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_InitStructure.GPIO_Pin = ALL_LED_PINS;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
	
	GPIO_SetBits(GPIOB,ALL_LED_PINS);
	
}

void Flow_Update(void)
{
	if (Speed > 0)
	{
		GPIO_SetBits(GPIOB,ALL_LED_PINS);
		GPIO_ResetBits(GPIOB,led_pins[current_index]);
		Delay_ms(200);
		current_index = (current_index + 1) % 4;
	}
	else if(Speed < 0)
	{
		GPIO_SetBits(GPIOB,ALL_LED_PINS);
		GPIO_ResetBits(GPIOB,led_pins[current_index]);
		Delay_ms(200);
		current_index = (current_index == 0) ? 3 : (current_index - 1);
	}
	else if(Speed == 0)
	{
		GPIO_SetBits(GPIOB,ALL_LED_PINS);
	}
}
